package com.dimong.www.loan.app;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.text.TextUtils;
import android.util.Log;
import android.view.WindowManager;

import com.dimong.loan.sdk.app.BaseApplication;
import com.dimong.loan.sdk.utils.Tool;
import com.dimong.loan.sdk.utils.UIUtils;
import com.dimong.loan.sdk.utils.Utils;
import com.dimong.www.loan.bean.UserIndexPageBean;
import com.dimong.www.loan.cache.UserIndexPageCache;
import com.dimong.www.loan.ui.act.account.RegisterFirstActivity;

import java.util.Map;

public class MyApplication extends BaseApplication {
    private static Context sContext;
    public static UserIndexPageBean userBean = null;

    public static Context getAppContext() {
        return sContext;
    }

    @Override
    public void initAppParam() {
        UIUtils.initDisplayMetrics(getApplicationContext(),
            (WindowManager) getApplicationContext().getSystemService(Context.WINDOW_SERVICE), true);

    }

    @Override
    public void initThirdLibrary() {
    }

    @Override
    public void onAppLowMemory() {

    }

    @Override
    public void onAppTerminate() {

    }

    @Override
    public void initDBHelper() {

    }

    @Override
    public void initDirectory() {

    }

    @Override
    public void initPushError() {

    }

    @Override
    public void initNet() {

    }

    @Override
    public void setDebug() {

    }

    @Override
    public void initImageLoader() {

    }

    @Override
    public void onAppBackground() {

    }

    @Override
    public void onAppForeground(Activity activity) {

    }

    @Override
    public boolean isCurProcess() {
        return Utils.getCurProcessName(this).equals("com.dimong.www.loan");
    }

    @Override
    public void onAllProgressInit() {

    }

    @Override
    public void initUserInfoFromDB() {

    }

    @Override
    public void initSharedPreferences() {

    }

    @Override
    public Map<String, String> getHttpHeaders() {
        return null;
    }

    @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        sContext = base;
    }

    public static void logOut() {
//        AppManager.getInstance().reset();
//        DBHelper.getInstance().close();
//        JimiDBHelper.getInstance().getUserInfoDBHelper().logOut();
//
//        user = null;
//        BroadcastHelper.getInstance().sendBroadCast(sContext, BroadcastName.BROADCAST_ACTION_LOGOUT);
//        openLogin();
    }

    public static void openLogin() {
        Intent intent = new Intent(sContext, RegisterFirstActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        MyApplication.sContext.startActivity(intent);
    }

    public static boolean isLogin() {
        if (UserIndexPageCache.getInstance().getUserIndexPageBean() != null) {
            if (TextUtils.isEmpty(UserIndexPageCache.getInstance().getUserIndexPageBean().getPhone())) {
                return false;
            } else if ("立即登录".equals(UserIndexPageCache.getInstance().getUserIndexPageBean().getPhone())) {
                return false;
            } else {
                return true;
            }
        } else {
            return false;
        }
    }
}
